home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Utilities / DVIM72-Mac 1.9.6 / source / DISPCHAR.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-14  |  7.1 KB  |  223 lines  |  [TEXT/R*ch]

  1. /* -*-C-*- dispchar.h */
  2. /*-->dispchar*/
  3. /**********************************************************************/
  4. /****************************** dispchar ******************************/
  5. /**********************************************************************/
  6. #include "dvihead.h"
  7. #include "commands.h"
  8. #include "gendefs.h"
  9. #include "gblprocs.h"
  10. #include "egblvars.h"
  11. #include "m72.h"
  12. #include "mac-specific.h"
  13. #include "Scale_rect.h"
  14.  
  15. void
  16. dispchar(c)        // called by setchar
  17. BYTE c;        /* character number in current font */
  18.  
  19. /***********************************************************************
  20.  
  21.    This procedure has the delicate  job of OR'ing the current  character
  22.    raster description into the bitmap,  where the character box  extends
  23.    horizontally from  (xcorner  ..  xcorner+wp-1)  and  vertically  from
  24.    (ycorner  ..   ycorner+hp-1).   The  lower  left  corner  coordinates
  25.    (xcorner, ycorner) are  related to  the current point  (xcp, ycp)  as
  26.    follows:
  27.  
  28.     <------wp------>
  29.     ^    ................
  30.     |    ................
  31.     |    ................
  32.     |    ................
  33.     |    ................
  34.     |    ................
  35.     |    ................
  36.     hp  ................
  37.     |    ................
  38.     |    ................
  39.     |    ................
  40.     |    .....o..........       <-- (xcp,ycp) at "o"
  41.     |    ................ ^
  42.     |    ................ |
  43.     |    ................ |--- (hp - yoffp - 1)
  44.     |    ................ |
  45.     v    +............... v     <-- (xcorner,ycorner) at "+"
  46.     <--->
  47.       |
  48.       |
  49.      xoffp
  50.  
  51.    The current PXL file format stores character rasters in 32-bit words,
  52.    with the rightmost portion of the  last word in each line beyond  the
  53.    edge of  the character  being all  0 bits.    For efficiency,  the  OR
  54.    operation is done a word  at a time, and  in general, each such  word
  55.    contributes to two words in the bitmap line.
  56.  
  57.          line            line           line
  58.    |.........word.........|.........word.........|.........word.........|
  59.  
  60.   32-bit chunks--> |.....chrast.....|.....chrast.....|.....chrast.....|
  61.  
  62.            |<---->|<------->|
  63.                |       |
  64.      bits_to_current---^       ^--- bits_to_next
  65.  
  66.    Thus, each  32-bit  chunk  will  be  right-shifted  (filling  vacated
  67.    positions at the left with 0 bits) leaving "bits_to_current" bits  at
  68.    the low end and then OR'd into the current word of the bitmap line.
  69.  
  70.    Since the C language  right-shift operator may  or may not  propagate
  71.    the sign bit  (which is usually  at the left),  a compile-time  flag,
  72.    ARITHRSHIFT, is necessary to include an extra AND operation to remove
  73.    them  when    the  right-shift   is  implemented   by  an   arithmetic
  74.    (sign-propagating), rather than a logical, shift.
  75.  
  76.    The 32-bit  chunk will  then  be left-shifted  (with 0  bits  filling
  77.    vacated positions on  the right) leaving  "bits_to_next" bits at  the
  78.    high end and OR'd into the next word of the bitmap line.
  79.  
  80.    When the host word  size exceeds 32 bits  (e.g. DEC-10 or -20  36-bit
  81.    word), the  first step  may in  fact require  a left  shift, and  the
  82.    second step is then not needed.   This is detected in the code  below
  83.    by "bits_to_next" being negative.
  84.  
  85. ***********************************************************************/
  86. {
  87.     register struct char_entry *tcharptr;
  88.     COORDINATE x,xcorner,ycorner;
  89.     UNSIGN16 ilimit;
  90.     register INT16 bits_to_next;
  91.     register UNSIGN16 i;
  92.     UNSIGN32 word32;
  93.     register UNSIGN32 *p;
  94.     register UNSIGN32 *raster_word;
  95.     register COORDINATE j;
  96. #if OS_THINKC
  97. #if PIXMAP
  98.     PixMap    char_map;
  99. #else
  100.     BitMap    char_map;
  101. #endif
  102.     Rect    dest, print_dest, preview_dest;
  103. #endif
  104.  
  105.     if ((c < FIRSTPXLCHAR) || (LASTPXLCHAR < c)) /* check character range */
  106.     return;
  107.  
  108.     tcharptr = &(fontptr->ch[c]);
  109.  
  110.     if (tcharptr->rasters == (UNSIGN32*)NULL)/* if rasters still on file */
  111.         loadchar(c);            /* go get them */
  112.     if (g_abort_dvi)
  113.         return;
  114.  
  115.     if (tcharptr->rasters == (UNSIGN32*)NULL)
  116.     return;    /* character image must be empty */
  117.  
  118.     tcharptr->refcount++;        /* update reference count */
  119.     raster_word = tcharptr->rasters;    /* pointer to first raster word */
  120.  
  121.     xcorner = xcp - tcharptr->xoffp;
  122.     ycorner = ycp - (tcharptr->hp - tcharptr->yoffp - 1);
  123.  
  124.     if (DBGOPT(DBG_CHAR_DUMP))
  125.     {
  126.         (void)printf(
  127.         "\ndispchar(): (xcp,ycp) = (%d,%d) (xcorner,ycorner) = (%d,%d)",
  128.         xcp,ycp,xcorner,ycorner);
  129.     (void)printf("\n            (wp,hp) = (%d,%d)  (xoffp,yoffp) = (%d,%d)\n",
  130.         tcharptr->wp,tcharptr->hp,tcharptr->xoffp,tcharptr->yoffp);
  131.         ilimit = (UNSIGN16)((tcharptr->wp + 31) >> 5);
  132.         for (j = tcharptr->hp; j > 0; --j)
  133.         {
  134.             for (i = 0; i < ilimit; ++i)
  135.                 (void)printf(" %08lx\n",*raster_word++);
  136.         }
  137.         raster_word = tcharptr->rasters;
  138.     }
  139. #if OS_THINKC /* New */
  140.     char_map.baseAddr = (Ptr) tcharptr->rasters;
  141.     char_map.rowBytes = ((tcharptr->wp + 31) >> 5) << 2;
  142.     SetRect( &char_map.bounds, 0, 0, tcharptr->wp, tcharptr->hp );
  143.  
  144. #if PIXMAP
  145.     char_map.rowBytes |= 0x8000;
  146.     char_map.pmVersion = 0;
  147.     char_map.packType = 0;
  148.     char_map.packSize = 0;
  149.     char_map.hRes = char_map.vRes = ((Fixed)g_dpi) << 16;
  150.     char_map.pixelType = 0;
  151.     char_map.pixelSize = 1;
  152.     char_map.cmpCount = 1;
  153.     char_map.cmpSize = 1;
  154.     char_map.planeBytes = 0L;
  155.     char_map.pmTable = GetCTable(1);
  156.     char_map.pmReserved = 0L;
  157. #endif
  158.     
  159.     SetRect( &dest, xcorner,
  160.         YSIZE - (ycorner + tcharptr->hp),
  161.         xcorner + tcharptr->wp,
  162.         YSIZE - ycorner );
  163.     if (g_draw_offscreen)
  164.     {
  165.         CopyBits( (BitMap *)&char_map, &g_offscreen_GrafPort.portBits,
  166.             &char_map.bounds, &dest, srcOr, NIL );
  167.     }
  168.     else
  169.     {
  170.         Scale_rect( &dest, &print_dest, &preview_dest );
  171.         if (g_preview)
  172.         {
  173.             SetPort( g_page_window );
  174.             /* We use srcCopy instead of srcOr here for speed. */
  175.             CopyBits( (BitMap *)&char_map, &g_page_window->portBits,
  176.                 &char_map.bounds, &preview_dest, srcCopy, NIL );
  177.         }
  178.         SetPort( (GrafPtr) g_print_port_p );
  179.         CopyBits( (BitMap *)&char_map, &g_print_port_p->gPort.portBits,
  180.             &char_map.bounds, &print_dest, srcOr, nil );
  181.     }
  182. #else
  183. #if OS_THINKC
  184.     for (j = tcharptr->hp; j > 0; --j)    /* loop over hp rasters from */
  185.     {                    /* top to bottom */
  186.     x = xcorner;            /* select horizontal position */
  187.     p = BITMAP(ycorner+1 - j,x/HOST_WORD_SIZE); /* and find word on line */
  188. #else
  189.     for (j = tcharptr->hp; j > 0; --j)    /* loop over hp rasters from */
  190.     {                    /* top to bottom */
  191.     x = xcorner;            /* select horizontal position */
  192.     p = BITMAP(ycorner+j-1,x/HOST_WORD_SIZE); /* and find word on line */
  193. #endif
  194.     ilimit = (UNSIGN16)((tcharptr->wp + 31) >> 5);
  195.     for (i = 0; i < ilimit; ++i)
  196.     {            /* loop over current line */
  197.         word32 = *raster_word++; /* get 32-bit portion of raster */
  198.         bits_to_next = (INT16)((x % HOST_WORD_SIZE) - HOST_WORD_SIZE + 32);
  199.  
  200. #if    (HOST_WORD_SIZE > 32)
  201.         if (bits_to_next < 0)   /* then must left shift character raster */
  202.         *p |= (word32 << (-bits_to_next));  /* and OR into line */
  203.         else
  204. #endif
  205.  
  206.         {
  207.         *p |=
  208.  
  209.               (word32 >> bits_to_next);     /* OR into line */
  210.  
  211.         if (bits_to_next > 0)
  212.             *++p |= (word32 << (HOST_WORD_SIZE - bits_to_next));
  213.                 /* OR in any spill into next word */
  214.         else if (bits_to_next == 0)
  215.             ++p;    /* ended at word boundary, so start new one */
  216.         }
  217.         x += 32;        /* and update horizontal position */
  218.     }
  219.     }
  220. #endif /* OS_THINKC New */
  221. }
  222.  
  223.